home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-STLport.exe / {app} / include / renderers / IrrlichtRenderer / irrlichtrenderer.h next >
Encoding:
C/C++ Source or Header  |  2005-02-16  |  10.5 KB  |  389 lines

  1. /************************************************************************
  2.     filename:     irrlichtrenderer.h
  3.     created:    20/7/2004
  4.     author:        Thomas Suter
  5. *************************************************************************/
  6. /*************************************************************************
  7.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  8.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  9.  
  10.     This library is free software; you can redistribute it and/or
  11.     modify it under the terms of the GNU Lesser General Public
  12.     License as published by the Free Software Foundation; either
  13.     version 2.1 of the License, or (at your option) any later version.
  14.  
  15.     This library is distributed in the hope that it will be useful,
  16.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.     Lesser General Public License for more details.
  19.  
  20.     You should have received a copy of the GNU Lesser General Public
  21.     License along with this library; if not, write to the Free Software
  22.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23. *************************************************************************/
  24. #ifndef _CEGUI_IrrlichtRenderer_h_
  25. #define _CEGUI_IrrlichtRenderer_h_
  26.  
  27. #include "IrrlichtRendererDef.h"
  28. #include "irrlichttexture.h"
  29. #include "IrrlichtResourceProvider.h"
  30.  
  31. #include "CEGUIRenderer.h"
  32. #include "CEGUIInputEvent.h"
  33.  
  34. #include <irrlicht.h>
  35.  
  36. #include <vector>
  37. #include <algorithm>
  38.  
  39. #if defined(_MSC_VER)
  40. #    pragma warning(push)
  41. #    pragma warning(disable : 4251)
  42. #endif
  43.  
  44. namespace CEGUI
  45. {
  46.  
  47.     class EventPusher;
  48.  
  49.     /*!
  50.     \brief
  51.     class implementing the interface for Renderer objects with 
  52.     the irrlicht graphics engine.
  53.     */
  54.     class IRRLICHT_GUIRENDERER_API IrrlichtRenderer: public Renderer
  55.     {
  56.     public:
  57.  
  58.         /*! constructor 
  59.         \brief create the irrlicht renderer
  60.  
  61.         \param dev 
  62.         pointer to irr::IrrlichtDevice value specifying the irrlicht device
  63.  
  64.         \param bWithIrrlichtResourceProvicer
  65.         bool specifying wether to use an irrlicht- or defautresourceprovider (default)
  66.         */
  67.  
  68.         IrrlichtRenderer(irr::IrrlichtDevice* dev,bool bWithIrrlichtResourceProvicer=false);
  69.  
  70.         /*!    destructor */
  71.         virtual ~IrrlichtRenderer();
  72.  
  73.         
  74.         /*! get an irrlicht resource provider
  75.         \return irrlicht resourceprovider
  76.         */
  77.         virtual ResourceProvider* createResourceProvider(void);
  78.  
  79.         /*! forward event to CEGUI system */
  80.         bool OnEvent(irr::SEvent& event);
  81.  
  82.  
  83.         /*************************************************************************
  84.         Abstract interface methods
  85.         *************************************************************************/
  86.         /*!
  87.         \brief
  88.         Add a quad to the rendering queue.  All clipping and other adjustments should have been made prior to calling this.
  89.  
  90.         \param dest_rect
  91.         Rect object describing the destination area (values are in pixels)
  92.  
  93.         \param z
  94.         float value specifying the z co-ordinate / z order of the quad
  95.  
  96.         \param tex
  97.         pointer to the Texture object that holds the imagery to be rendered
  98.  
  99.         \param texture_rect
  100.         Rect object holding the area of \a tex that is to be rendered (values are in texture co-ordinates).
  101.  
  102.         \param colours
  103.         ColourRect object describing the colour values that are to be applied when rendering.
  104.  
  105.         \param quad_split_mode
  106.         One of the QuadSplitMode values specifying the way quads are split into triangles
  107.  
  108.         \return
  109.         Nothing
  110.         */
  111.         virtual    void    addQuad(const Rect& dest_rect, float z, const Texture* tex, 
  112.             const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
  113.  
  114.  
  115.         /*!
  116.         \brief
  117.         Perform final rendering for all quads that have been queued for rendering
  118.  
  119.         The contents of the rendering queue is retained and can be rendered again as required.  If the contents is not required call clearRenderList().
  120.  
  121.         \return
  122.         Nothing
  123.         */
  124.         virtual    void    doRender(void);
  125.  
  126.  
  127.         /*!
  128.         \brief
  129.         Clears all queued quads from the render queue.
  130.  
  131.         \return
  132.         Nothing
  133.         */
  134.         virtual    void    clearRenderList(void);
  135.  
  136.  
  137.         /*!
  138.         \brief
  139.         Enable or disable the queueing of quads from this point on.
  140.  
  141.         This only affects queueing.  If queueing is turned off, any calls to addQuad will cause the quad to be rendered directly.  Note that
  142.         disabling queueing will not cause currently queued quads to be rendered, nor is the queue cleared - at any time the queue can still
  143.         be drawn by calling doRender, and the list can be cleared by calling clearRenderList.  Re-enabling the queue causes subsequent quads
  144.         to be added as if queueing had never been disabled.
  145.  
  146.         \param setting
  147.         true to enable queueing, or false to disable queueing (see notes above).
  148.  
  149.         \return
  150.         Nothing
  151.         */
  152.         virtual void    setQueueingEnabled(bool setting);
  153.  
  154.  
  155.         /*!
  156.         \brief
  157.         Creates a 'null' Texture object.
  158.  
  159.         \return
  160.         a newly created Texture object.  The returned Texture object has no size or imagery associated with it, and is
  161.         generally of little or no use.
  162.         */
  163.         virtual    Texture*    createTexture(void);
  164.  
  165.  
  166.         /*!
  167.         \brief
  168.         Create a Texture object using the given image file.
  169.  
  170.         \param filename
  171.         String object that specifies the path and filename of the image file to use when creating the texture.
  172.  
  173.         \param resourceGroup
  174.         Resource group identifier passed to the resource provider.
  175.  
  176.         \return
  177.         a newly created Texture object.  The initial contents of the texture memory is the requested image file.
  178.  
  179.         \note
  180.         Textures are always created with a size that is a power of 2.  If the file you specify is of a size that is not
  181.         a power of two, the final size will be rounded up.  Additionally, textures are always square, so the ultimate
  182.         size is governed by the larger of the width and height of the specified file.  You can check the ultimate sizes
  183.         by querying the texture after creation.
  184.         */
  185.         virtual    Texture*    createTexture(const String& filename, const String& resourceGroup);
  186.  
  187.  
  188.         /*!
  189.         \brief
  190.         Create a Texture object with the given pixel dimensions as specified by \a size.  NB: Textures are always square.
  191.  
  192.         \param size
  193.         float value that specifies the size to use for the width and height when creating the new texture.
  194.  
  195.         \return
  196.         a newly created Texture object.  The initial contents of the texture memory is undefined / random.
  197.  
  198.         \note
  199.         Textures are always created with a size that is a power of 2.  If you specify a size that is not a power of two, the final
  200.         size will be rounded up.  So if you specify a size of 1024, the texture will be (1024 x 1024), however, if you specify a size
  201.         of 1025, the texture will be (2048 x 2048).  You can check the ultimate size by querying the texture after creation.
  202.         */    
  203.         virtual    Texture*    createTexture(float size);
  204.  
  205.  
  206.         /*!
  207.         \brief
  208.         Destroy the given Texture object.
  209.  
  210.         \param texture
  211.         pointer to the Texture object to be destroyed
  212.  
  213.         \return
  214.         Nothing
  215.         */
  216.         virtual    void        destroyTexture(Texture* texture);
  217.  
  218.  
  219.         /*!
  220.         \brief
  221.         Destroy all Texture objects.
  222.  
  223.         \return
  224.         Nothing
  225.         */
  226.         virtual void        destroyAllTextures(void);
  227.  
  228.  
  229.         /*!
  230.         \brief
  231.         Return whether queueing is enabled.
  232.  
  233.         \return
  234.         true if queueing is enabled, false if queueing is disabled.
  235.         */
  236.         virtual bool    isQueueingEnabled(void) const;
  237.  
  238.  
  239.         /*!
  240.         \brief
  241.         Return the current width of the display in pixels
  242.  
  243.         \return
  244.         float value equal to the current width of the display in pixels.
  245.         */
  246.         virtual float    getWidth(void) const;
  247.  
  248.  
  249.         /*!
  250.         \brief
  251.         Return the current height of the display in pixels
  252.  
  253.         \return
  254.         float value equal to the current height of the display in pixels.
  255.         */
  256.         virtual float    getHeight(void) const;
  257.  
  258.  
  259.         /*!
  260.         \brief
  261.         Return the size of the display in pixels
  262.  
  263.         \return
  264.         Size object describing the dimensions of the current display.
  265.         */
  266.         virtual Size    getSize(void) const;
  267.  
  268.  
  269.         /*!
  270.         \brief
  271.         Return a Rect describing the screen
  272.  
  273.         \return
  274.         A Rect object that describes the screen area.  Typically, the top-left values are always 0, and the size of the area described is
  275.         equal to the screen resolution.
  276.         */
  277.         virtual Rect    getRect(void) const;
  278.  
  279.  
  280.         /*!
  281.         \brief
  282.         Return the maximum texture size available
  283.  
  284.         \return
  285.         Size of the maximum supported texture in pixels (textures are always assumed to be square)
  286.         */
  287.         virtual    uint    getMaxTextureSize(void) const;
  288.  
  289.  
  290.         /*!
  291.         \brief
  292.         Return the horizontal display resolution dpi
  293.  
  294.         \return
  295.         horizontal resolution of the display in dpi.
  296.         */
  297.         virtual    uint    getHorzScreenDPI(void) const;
  298.  
  299.  
  300.         /*!
  301.         \brief
  302.         Return the vertical display resolution dpi
  303.  
  304.         \return
  305.         vertical resolution of the display in dpi.
  306.         */
  307.         virtual    uint    getVertScreenDPI(void) const;
  308.  
  309.         private:
  310.  
  311.             // the irrlicht device
  312.             irr::IrrlichtDevice* device;
  313.             // video driver
  314.             irr::video::IVideoDriver* driver;
  315.             // window width,height
  316.             irr::core::dimension2d<irr::s32> resolution;
  317.             // screen resolution
  318.             irr::core::dimension2d<irr::s32> screensize;
  319.  
  320.             // is queueing enabled
  321.             bool bQueuingEnabled;
  322.             // is quad queue sorted
  323.             bool bSorted;
  324.             // enable irrlicht resource provider
  325.             bool bWithIrrlichtResourceProvicer;
  326.  
  327.             // quad structure used for rendering the gui
  328.             struct RenderQuad
  329.             {
  330.                 RenderQuad(){};
  331.  
  332.                 RenderQuad(float zVal, 
  333.                     const irr::core::rect<irr::s32>& target,
  334.                     const irr::core::rect<irr::s32>& source,
  335.                     ColourRect col,const Texture*t)
  336.                     :z(zVal),dst(target),src(source),colours(col){
  337.                         tex=(IrrlichtTexture*)t;
  338.                     };
  339.  
  340.                 float z;
  341.                 irr::core::rect<irr::s32> dst;
  342.                 irr::core::rect<irr::s32> src;
  343.                 ColourRect colours;
  344.                 IrrlichtTexture* tex;
  345.             };
  346.  
  347.             RenderQuad dummyQuad;
  348.  
  349.             // std sorting RenderQuad class
  350.             struct quadsorter
  351.                 : public std::binary_function<RenderQuad*, RenderQuad*, bool>
  352.             {
  353.                 bool operator()(const RenderQuad& _Left, const RenderQuad& _Right) const
  354.                 {return (_Left.z > _Right.z);}
  355.             };
  356.  
  357.             // list ot quads we want to render
  358.             std::vector<RenderQuad> renderlist;
  359.  
  360.             // list of textures used for rendering
  361.             std::vector<IrrlichtTexture*> textures;
  362.  
  363.             // sort the quads in the renderlist
  364.             void sortQuads();
  365.  
  366.             // render the quad
  367.             void doRender(RenderQuad& quad);
  368.  
  369.             // print some debug output
  370.             void print(RenderQuad& quad);
  371.  
  372.             // convert cegui colour to irrlicht scolor
  373.             inline irr::video::SColor toIrrlichtColor(CEGUI::ulong cecolor);
  374.             irr::video::SColor colors[4];
  375.  
  376.  
  377.  
  378.             EventPusher* eventpusher;
  379.  
  380.     };
  381.  
  382. } // End of  CEGUI namespace section
  383.  
  384. #if defined(_MSC_VER)
  385. #    pragma warning(pop)
  386. #endif
  387.  
  388. #endif
  389.